﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class Message
    {
        private readonly Chain.IDAL.Message dal = new Chain.IDAL.Message();

        public int Add(Chain.Model.Message model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.Message> DataTableToList(DataTable dt)
        {
            List<Chain.Model.Message> list = new List<Chain.Model.Message>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.Message item = new Chain.Model.Message();
                    if ((dt.Rows[i]["MessageID"] != null) && (dt.Rows[i]["MessageID"].ToString() != ""))
                    {
                        item.MessageID = int.Parse(dt.Rows[i]["MessageID"].ToString());
                    }
                    if ((dt.Rows[i]["MessageMemID"] != null) && (dt.Rows[i]["MessageMemID"].ToString() != ""))
                    {
                        item.MessageMemID = int.Parse(dt.Rows[i]["MessageMemID"].ToString());
                    }
                    if ((dt.Rows[i]["MessageContent"] != null) && (dt.Rows[i]["MessageContent"].ToString() != ""))
                    {
                        item.MessageContent = dt.Rows[i]["MessageContent"].ToString();
                    }
                    if ((dt.Rows[i]["MessageTime"] != null) && (dt.Rows[i]["MessageTime"].ToString() != ""))
                    {
                        item.MessageTime = DateTime.Parse(dt.Rows[i]["MessageTime"].ToString());
                    }
                    if ((dt.Rows[i]["MessageIsReply"] != null) && (dt.Rows[i]["MessageIsReply"].ToString() != ""))
                    {
                        item.MessageIsReply = int.Parse(dt.Rows[i]["MessageIsReply"].ToString());
                    }
                    if ((dt.Rows[i]["MessageReplyContent"] != null) && (dt.Rows[i]["MessageReplyContent"].ToString() != ""))
                    {
                        item.MessageReplyContent = dt.Rows[i]["MessageReplyContent"].ToString();
                    }
                    if ((dt.Rows[i]["MessageReplyTime"] != null) && (dt.Rows[i]["MessageReplyTime"].ToString() != ""))
                    {
                        item.MessageReplyTime = DateTime.Parse(dt.Rows[i]["MessageReplyTime"].ToString());
                    }
                    if ((dt.Rows[i]["MessageReplyUserID"] != null) && (dt.Rows[i]["MessageReplyUserID"].ToString() != ""))
                    {
                        item.MessageReplyUserID = int.Parse(dt.Rows[i]["MessageReplyUserID"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int MessageID)
        {
            return this.dal.Delete(MessageID);
        }

        public bool DeleteList(string MessageIDlist)
        {
            return this.dal.DeleteList(MessageIDlist);
        }

        public bool Exists(int MessageID)
        {
            return this.dal.Exists(MessageID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, out resCount, strWhere);
        }

        public DataSet GetListSPInfo(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSPInfo(PageSize, PageIndex, out resCount, strWhere);
        }

        public int GetMaxId()
        {
            return this.dal.GetMaxId();
        }

        public DataSet GetMemMessageList(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetMemMessageList(PageSize, PageIndex, out resCount, strWhere);
        }

        public DataSet GetMessenger(string strWhere)
        {
            return this.dal.GetMessenger(strWhere);
        }

        public Chain.Model.Message GetModel(int MessageID)
        {
            return this.dal.GetModel(MessageID);
        }

        public List<Chain.Model.Message> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public int MessageDel(int intMemID)
        {
            return this.dal.MessageDel(intMemID);
        }

        public bool Reply(Chain.Model.Message modelMessage)
        {
            return this.dal.Reply(modelMessage);
        }

        public bool Update(Chain.Model.Message model)
        {
            return this.dal.Update(model);
        }
    }
}

